// pages/allinpay.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    "appid": "00308262",
    "body": "iPhone15",
    "cusid": "563881053992LU7",
    "notify_url": "https://dev.xjzdxxkj.com/allinpay/notify",
    "paytype": "W06",
    "randomstr": "pMQzUJK6IkESj9otrGKs56UWlOdRF7_U",
    "reqsn": "BZJ268337679433859073",
    "sign": "A7gR3IRCTFtsbuMJEkAC0lP7Mlyi4PjbHBCxdcxHWTvx93MEAOogp+mfczHKtlYDHQ2ERix3R5mZ3hxKhOx4mqdz2ZEFQLDzlWP1BgUACfOSOEZO9lMehQhoraZNzUid5J0lwUkiYAlIXD2mS5IH5pr2LqCAE/iWMhGHV1iPTlEhVESnWQA0V8Dg1yAxa3rSvO1yq8igA2PCh3xqSZ2KYklH3aF0wy6iOvyPtsrd/oJuWR/4ceOOW/Me4egT73qXJjUu5PLDZboiMm6ZUPieQ2xATc55LGUHn18sxnfEb1N+mvzMFGfvNGHRp5ql32ez9n2HUaYblqMmII9m3Q6Yaw==",
    "signtype": "RSA",
    "trxamt": "1",
    "version": "12"
  },
  compareVersion(v1, v2) {
    v1 = v1.split('.')
    v2 = v2.split('.')
    const len = Math.max(v1.length, v2.length)
    while (v1.length < len) {
      v1.push('0')
    }
    while (v2.length < len) {
      v2.push('0')
    }
    for (let i = 0; i < len; i++) {
      const num1 = parseInt(v1[i])
      const num2 = parseInt(v2[i])
      if (num1 > num2) {
        return 1
      } else if (num1 < num2) {
        return -1
      }
    }
    return 0
  },
  /**
   * 支付
   * */
  goPay() {
    let params = this.data;
    const version = wx.getAppBaseInfo().SDKVersion;
    if (this.compareVersion(version, '2.26.2') >= 0) {
      console.log(version);
      wx.openEmbeddedMiniProgram({
        appId: 'wxef277996acc166c3',
        extraData: params
      });
    } else {
      wx.navigateToMiniProgram({
        appId: 'wxef277996acc166c3',
        extraData: params
      });
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let options = wx.getEnterOptionsSync();
    if (options.scene == '1038' &&
      options.referrerInfo.appId == 'wxef277996acc166c3') {
      // 代表从收银台小程序返回
      let extraData = options.referrerInfo.extraData;
      if (!extraData) {
        // "当前通过物理按键返回，未接收到返参，建议自行查询交易结果";
      } else {
        if (extraData.code == 'success') {
          // "支付成功";
        } else if (extraData.code == 'cancel') {
          // "支付已取消";
        } else {
          // "支付失败：" + extraData.errmsg;
        }
      }
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})